package io.renren.modules.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.demo.dao.DhSportapplyInfoDao;
import io.renren.modules.demo.dto.DhSportapplyInfoDTO;
import io.renren.modules.demo.entity.DhSportapplyInfoEntity;
import io.renren.modules.demo.service.DhSportapplyInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2023-03-25
 */
@Service
public class DhSportapplyInfoServiceImpl extends CrudServiceImpl<DhSportapplyInfoDao, DhSportapplyInfoEntity, DhSportapplyInfoDTO> implements DhSportapplyInfoService {

    @Autowired
    private DhSportapplyInfoDao dhSportapplyInfoDao;

    @Override
    public QueryWrapper<DhSportapplyInfoEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<DhSportapplyInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    /**
     * 根据户外运动编号获取户外报名信息
     *
     * @param sportId
     * @return
     */
    @Override
    public DhSportapplyInfoDTO getSportApplyInfo(Integer sportId) {
        LambdaQueryWrapper<DhSportapplyInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select().eq(DhSportapplyInfoEntity::getSportId, sportId);
        List<DhSportapplyInfoEntity> list = dhSportapplyInfoDao.selectList(queryWrapper);
        DhSportapplyInfoDTO dhSportapplyInfoDTO = new DhSportapplyInfoDTO();
        for (DhSportapplyInfoEntity dhSportapplyInfoEntity : list) {
            dhSportapplyInfoDTO.setSportId(dhSportapplyInfoEntity.getSportId());
            dhSportapplyInfoDTO.setUserId(dhSportapplyInfoEntity.getUserId());
        }
        return dhSportapplyInfoDTO;
    }
}